

//package com.misi.controller.admin.role;
package com.alex.web.controller.member;
import com.alex.web.annotation.ExceptionFeedback;
import com.alex.web.bean.CommonResult;
import com.alex.web.bean.member.RolePermission;
import com.alex.web.controller.base.BaseController;
import com.alex.web.db.domain.PageInfo;
import com.alex.web.db.domain.PageControl;
//import com.alex.web.log.MISILogger;
//import com.alex.web.log.MISILoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestParam;
import com.alex.web.service.RolePermissionService;

/**
 * 
 * @author 密思软件
 * @date 2018-8-26 17:48:38
 */
@Controller
@RequestMapping(value = "/business/rolePermission")
public class RolePermissionController extends BaseController {

//	private static final MISILogger logger = MISILoggerFactory.getLogger(RolePermissionController.class);

    @Autowired
    private RolePermissionService rolePermissionService;
	/**
	 * 跳转到列表页面
	 * @param model
	 * @return
	 */
	@ExceptionFeedback(errorMsg = "查询列表异常")		//定义异常提示消息
	@RequestMapping("/")
	public String index(Model model){
		return getPage(model,1);
		}



	/**
	 * 跳转到指定页面
	 * @param model
	 * @return
	 */
	@ExceptionFeedback(errorMsg = "列表分页查询异常")		//定义异常提示消息
	@RequestMapping("/page")
	public String getPage(Model model,int page){
		RolePermission entity = new RolePermission();
		PageInfo info = new PageInfo(page>0?page-1:0);
		PageControl<RolePermission> control = rolePermissionService.page(entity,info,null,null);
		model.addAttribute("page",control);
		return "v1/business/rolePermission/list";
	}
	/**
	 * 根据id 查找
	 * @param id
	 * @return son数据
	 */
	@ExceptionFeedback(errorMsg = "根据id查找异常")		//定义异常提示消息
	@RequestMapping("/get")
	@ResponseBody
	public CommonResult getRolePermission(@RequestParam(name = "id", required = true)Integer id){
		if (id > 0){
			RolePermission entity =  rolePermissionService.find(id);
			return CommonResult.successResult(entity);
		}else{
			return CommonResult.exceptionResult("无法解析传入对象！");
		}
	}

	/**
	 * 提交新增请求
	 * @param entity
	 * @param model
	 * @return
	 */
	@ExceptionFeedback(errorMsg = "新增异常")		//定义异常提示消息
	@RequestMapping(value = "/add",method = RequestMethod.POST)
	@ResponseBody
	public CommonResult addRolePermission(RolePermission entity, Model model){
		if (entity!=null){
			int nun=0;
			nun = rolePermissionService.insertRolePermission(entity);
			if (nun <= 0) {
				return CommonResult.exceptionResult("数据更新失败。");
			}
			return CommonResult.successResult("更新成功！");
		}else {
			return CommonResult.exceptionResult("无法解析传入对象！");
		}
	}
	/**
	 * 提交修改请求
	 * @param entity
	 * @param model
	 * @return
	 */
	@ExceptionFeedback(errorMsg = "修改异常")		//定义异常提示消息
	@RequestMapping(value = "/edit",method = RequestMethod.POST)
	@ResponseBody
	public CommonResult editRolePermission(RolePermission entity,Model model){
		if (entity!=null){
			int nun = 0;
			nun = rolePermissionService.updateRolePermission(entity);
			if (nun <= 0) {
				return CommonResult.exceptionResult("数据更新失败。");
			}
			return CommonResult.successResult("更新成功！");
		}else {
			return CommonResult.exceptionResult("无法解析传入对象！");
		}
	}
	/**
	 * 根据id删除
	 * @param id
	 * @return
	 */
	@ExceptionFeedback(errorMsg = "删除异常")		//定义异常提示消息
	@RequestMapping("/del")
	@ResponseBody
	public CommonResult delRolePermission(@RequestParam(name = "id", required = true)int id){
		int nun = 0;

		nun = rolePermissionService.delete(id);
		if (nun <= 0) {
			return CommonResult.exceptionResult("删除失败。");
		}
		return CommonResult.successResult("删除成功！");
	}


}
